
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jard.webshop.jsfbeans;

import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;

/**
 *
 * @author cjp
 */
@ManagedBean(name="fileUploadController")
@RequestScoped
public class FileUploadController {

    /** Creates a new instance of FileUploadController */
    public FileUploadController() {
        System.out.println("FileUploadController created!");
    }
    
    public void handleFileUpload(FileUploadEvent evt) {
        BufferedWriter buff = null;
        try {
            UploadedFile upFile = evt.getFile();
            File file = new File(upFile.getFileName());
            System.out.println("File => " +  file.getAbsolutePath());
            FileOutputStream fos = new  FileOutputStream(file);
            fos.write(upFile.getContents());
            fos.flush();
            fos.close();
        } catch (IOException ex) {
            System.out.println("Darned!");
        }
    }
}
